<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/commons/include/html_doctype.html" %>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<%@include file="/commons/page/codegen.jsp" %>
		<script type="text/javascript" src="${ctx}/js/gpoint/rdp/SearchController/searchController.js"></script>
		<title>TB_DOOR_CTL_SEARCHCONTROLLER管理列表</title>
	</head>
	<body>
		<div class="wrapper wrapper-content  animated fadeInRight col-sm-12">
			<div  class="toolbar-panel ">
				<div class="toolbar-box">
					<div class="toolbar-head clearfix">
						<!-- 顶部按钮 -->
						<div class="buttons"> 		
							<a class="btn btn-primary fa"   onClick="addController();"> <span>添加搜索到的控制器</span></a>

                            <a class="btn btn-primary fa"    onClick="netController();"> <span>搜索同网段控制器</span></a>	
                            
					        <a class="btn btn-primary fa"    onClick="editController();"> <span>修改控制器的网络参数</span></a>	
					        
					        
					        

					      
						</div>
						<!-- 收缩 -->
						<div class="tools">
							<a href="javascript:void(0);" class="collapse">
								<i class="bigger-180 fa  fa-angle-double-up"></i>
							</a>
						</div>
					</div>
					<!-- #查询条件-->
					<div class="toolbar-body" >
						<form role="form" class="search-form">
							<div  class="form-inline p-xxs">

							</div>
						</form>
					</div><!--/ 查询条件-->
				</div>
			</div><!--/ 操作、查询-->
			<div class="jqGrid_wrapper">
				<table id="searchControllerGrid" ></table>
				<!-- 
				<div id="searchControllerPager"></div>
				 -->
			</div>
		</div>
		<script type="text/javascript">	   
		   var grid; 
		   var getUrl = "${getUrl}";
		   $(function(){
			   grid = $("#searchControllerGrid");  
			   
		   });
 
		  function netController(){     
			   refreshGrid();			   
		   }
		  
		   function refreshGrid(){		   
			   grid.jqGrid('clearGridData');  //清空表格
			   grid.jqGrid('setGridParam',{
				   // datatype: "local",
				   // data:data
				    url:'${ctx}/rdp/SearchController/searchController/listJson'
			   }).trigger("reloadGrid");	
		   }
		   
		   function getSelectedRowDatas(ids){
			   var datas = [];
			   ids.forEach(function (item, index) {
				   var rowData=grid.jqGrid("getRowData",item);
				   datas.push(rowData);
			   });
			   return datas;
		   }
		   
		   
				
		   function addController(){
			   //获取选中的行数据
			   var ids = grid.jqGrid('getGridParam','selarrrow');
		       if(ids.length < 1){
		    	   DialogUtil.confirm("请选择要添加的数据");
		    	   return;
		       }
			   var datas = getSelectedRowDatas(ids);
			   
			   //var datas = grid.jqGrid('getRowData');
			   var map = {};
			   map.datas=datas;
			   
			   $.ajax({
					url : "${ctx}/rdp/SearchController/searchController/save.htm",
					type : "POST",
					contentType : "application/json",
					data:JSON.stringify(map),
					dataType : "json",
					async : false,
					success : function(data) {
						DialogUtil.msg(data.message);
					},
					error:function(xhr,textStatus){
						DialogUtil.error("保存失败");
					}
			   
				});	   
		   }
		   
		   function editController(){
			   //获取选中row数据
			   var ids = grid.jqGrid('getGridParam','selarrrow');
		       if(ids.length != 1){
		    	   DialogUtil.confirm("请选择一个选项");
		    	   return;
		       }
		        var rowData=grid.jqGrid("getRowData",ids[0]);
		        var productid = ids[0] ;
				var productsn=rowData.productsn;
				var pcip=rowData.pcip;
				var submask=rowData.submask;
				var gateway=rowData.gateway;
				var port=rowData.port;
				var mac=rowData.mac;
				var yourip=rowData.yourip;
				var notes=rowData.notes;
				var paramStr="productid="+productid+"&productsn="+productsn+"&pcip="+pcip+"&submask="+submask
				            +"&gateway="+gateway+"&port="+port+"&mac="+mac+"&yourip="+yourip+"&notes="+notes;

			   DialogUtil.dialog(
					     
 
						 {
				 				title : "搜索控制器",
				 				content : '${ctx}/rdp/SearchController/searchController/netEdit.htm?'+paramStr,
				 				area : [ '400px', '500px' ],
				 				maxmin : false,
				 				btn : [ 
						 					{
												label : '保存',
												iconCls : 'btn btn-primary fa fa-save',
												action : function(dialog, index) {
													          DialogUtil.getChildFrameWindow(index).editController(index,function(){
													        	  DialogUtil.close(index);
													          });
												}
										    }, 
										    {
												label : '取消',
												iconCls : 'btn btn-primary fa fa-cancel',
												action : function(dialog, index) {
													DialogUtil.close(index);
												}
										    } 
										    
								],
				 				end : function() {
				 					 refreshGrid();
								}
				 			
				 		}
			  );
		   }

		</script>
	
	</body>
	
</html>